#ifndef __APP_DEVICE_H__
#define __APP_DEVICE_H__

#include "app_buffer.h"
#include <pthread.h>
#include "app_message.h"

struct DeviceFunc;

typedef struct DeviceObj
{
    ConnectionType type;     // 设备的连接类型
    Buffer *input_buffer;    // 设备的输入缓存
    Buffer *output_buffer;   // 设备的输出缓存
    char *name;              // 设备的文件名称
    int fd;                  // 设备的文件描述符
    pthread_t read_thread;   // 设备后台的读线程
    struct DeviceFunc *func; // 设备的函数指针
} Device;

struct DeviceFunc
{
    size_t (*postRead)(Device *, char *, size_t);
    size_t (*preWrite)(Device *, char *, size_t);
};

Device *app_device_init(char *dev_name);

int app_device_start(Device *dev);

int app_device_stop(Device *dev);

void app_device_deinit(Device *dev);

int app_device_write(Device *dev, void *data, size_t len);

#endif /* __APP_DEVICE_H__ */